// pages/menu-detail/menu-detail.js
import {reqgetPlaylistHot, reqgetHotSongsList} from "../../service/homeMusic"
Page({
  data: {
    songMenus: []
  },

  onLoad(options) {
    this.getPlaylistHot()
  },

  // 1、获取热门歌单分类
  async getPlaylistHot(){
    const tagRes = await reqgetPlaylistHot()
    const tags = tagRes.tags

    // 2、根据tags获取相应歌单
    const allPromise = []
    for(const tag of tags){
      // const res = reqgetHotSongsList(tag.name), 返回的是一个Promise
      const promise = reqgetHotSongsList(tag.name)
      allPromise.push(promise)
    }
    // 3.获取到所有的数据之后, 调用一次setData
    Promise.all(allPromise).then(res =>{
      this.setData({songMenus: res})
    })
  }
})
